package com.klondike.common;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class DynamicAttributesSupport<K> implements HasDynamicAttrs<K> {

    protected final Map<K, Object> attrs;

    public DynamicAttributesSupport() {
        attrs = new LinkedHashMap<K, Object>();
    }

    @Override
    public final <T> T getAttr(K attribute) {
        return (T) attrs.get(attribute);
    }

    @Override
    public final <T> T setAttr(K attribute, T value) {
        return (T) attrs.put(attribute, value);
    }

    @Override
    public final Set<K> attributes() {
        return Collections.unmodifiableSet(attrs.keySet());
    }

    @Override
    public final <T> T removeAttr(K attribute) {
        return (T) attrs.remove(attribute);
    }

}
